﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using System.Threading;
using DTO;

namespace DAO
{
    public class NhanVienDAO
    {
        public List<NhanVienDTO> LayDanhSachNhanVienDAO()
        {
            List<NhanVienDTO> listNV = new List<NhanVienDTO>();
            SqlConnection conn = null;
            SqlDataReader reader = null;
            try
            {
                String sql = "Select * from NhanVien";

                conn = DataProvider2.ConnectDB();
                SqlCommand cm = new SqlCommand(sql, conn);
                reader = cm.ExecuteReader();
                while (reader.Read())
                {
                    NhanVienDTO nvDTO = new NhanVienDTO();
                    nvDTO.ID_NhanVien = reader.GetInt32(0);
                    nvDTO.TenNhanVien = reader.GetString(1);
                    nvDTO.TenDangNhap = reader.GetString(2);
                    nvDTO.MatKhau = reader.GetString(3);
                    nvDTO.ID_ChucVu = reader.GetInt32(4);

                    listNV.Add(nvDTO);
                }
            }
            catch (Exception ex)
            { String e = ex.ToString(); }
            finally
            { conn.Close(); }
            return listNV;
        }
    }
}
